<?php
class Line_order_complain_model extends CI_Model
{
    private $table = 'line_order_complain';
    
    public function insertLineOrderComplain($postData)
    {
        $data = array(
            'order_id'         => $postData['order_id'],
            'product_id'       => $postData['product_id'],
            'complain_status'  => 1,//1：投诉；2：撤诉；3：同意撤诉
            'complain_name'    => $postData['complain_name'],
            'complain_tel'     => $postData['complain_tel'],
            'complain_content' => $postData['complain_content'],
            'agree_content'    => '',
        );
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }
    
    /**
     * 验证用户是否投诉
     * @param unknown $order_id
     */
    public function validateResellerComplain($order_id)
    {
        $this->db->where('order_id', $order_id);
        $result = $this->db->get($this->table);
        if ($result->num_rows() > 0) {
            return $result->row(0);
        }
        return false;
    }
    
    /**
     * 获取订单投诉详情
     * @param unknown $order_id
     */
    public function getComplainDetailByOrderId($order_id)
    {
        $this->db->where('order_id', $order_id);
        return $this->db->get($this->table);
    }
    
    public function updateLineOrderComplain($order_id, $complain_status)
    {
        $data = array(
            'complain_status' => $complain_status,
        );
        $this->db->where('order_id', $order_id);
        return $this->db->update($this->table, $data);
    }
}
